<template>
    <div>
      <el-form label-width="120px">
        <el-form-item label="选择模型">
          <el-select v-model="selectedModelIds" multiple placeholder="请选择">
            <el-option
              v-for="m in models"
              :key="m.id"
              :label="m.name"
              :value="m.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="测试数据">
          <el-input
            type="textarea"
            v-model="testData"
            placeholder="输入测试数据（如JSON、CSV等）"
            :rows="3"
          />
        </el-form-item>
        <el-form-item label="评估指标">
          <el-select v-model="metric">
            <el-option label="准确率" value="准确率" />
            <el-option label="召回率" value="召回率" />
            <el-option label="F1分数" value="F1分数" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="runAbTest">运行AB测试</el-button>
        </el-form-item>
      </el-form>
      <el-divider>AB测试记录</el-divider>
      <el-table :data="abTests" style="width: 100%;">
        <el-table-column prop="models" label="参与模型" :formatter="row => row.models.map(m=>m.name).join('、')" />
        <el-table-column prop="metric" label="评估指标" />
        <el-table-column prop="results" label="对比结果" :formatter="row => row.results.map(r => r.model + ': ' + r.value).join('；')" />
        <el-table-column prop="winner" label="最优模型" />
        <el-table-column prop="time" label="时间" />
      </el-table>
    </div>
  </template>
  
  <script>
  import { Message } from 'element-ui';
  export default {
    name: 'AbtestPanel',
    props: ['models', 'abTests'],
    data() {
      return {
        selectedModelIds: [],
        testData: '',
        metric: '准确率'
      };
    },
    methods: {
      runAbTest() {
        if (this.selectedModelIds.length < 2) {
          Message.warning('请至少选择两个模型');
          return;
        }
        if (!this.testData) {
          Message.warning('请填写测试数据');
          return;
        }
        this.$emit('run-abtest', {
          modelIds: this.selectedModelIds,
          testData: this.testData,
          metric: this.metric
        });
      }
    }
  };
  </script>